package com.mdd.front.controller;

import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.goods.IGoodsService;
import com.mdd.front.validate.PageParam;
import com.mdd.front.vo.goods.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 服务管理
 */
@Api(tags = "服务管理")
@RestController
@RequestMapping("api/goods")
public class GoodsController {

    @Resource
    IGoodsService iGoodsService;

    /**
     * 服务列表
     *
     * @param pageParam 分页参数
     * @param params    搜索参数
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 服务列表")
    @GetMapping("/list")
    public PageResult<GoodsListVo> list(@Validated PageParam pageParam,
                                        @RequestParam Map<String, String> params) {
        return iGoodsService.list(pageParam, params);
    }

    /**
     * @return java.lang.Object
     * @Author slien
     * @Description 统计状态数据
     * @Date 10:17 2022/10/7
     * @Param [pageParam, params]
     **/
    @Deprecated
    @ApiOperation(value = "服务管理 - 统计状态数据")
    @GetMapping("/statistics")
    public StatisticsGoodsVo statistics(@RequestParam Map<String, String> params) {
        return iGoodsService.statistics(params);
    }

    /**
     * 服务详情
     *
     * @param id 主键ID
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 服务详情")
    @GetMapping("/detail")
    public GoodsDetailVo detail(@Validated @RequestParam("id") Long id, @RequestParam(value = "cityId", required = false) Long cityId) {
        Long userId = Long.valueOf(LikeFrontThreadLocal.getUserId());
        return iGoodsService.detail(id, userId, cityId);
    }

    /**
     * 预约服务,返回对应的订单信息
     *
     * @param id 主键ID
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 预约服务")
    @GetMapping("/reserve")
    public OrderGoodsDetailVo reserveGoods(@Validated @RequestParam("id") Long id, @RequestParam("number") Integer number) {
        Assert.notNull(number, "数量不能为空");
        Integer userId = LikeFrontThreadLocal.getUserId();
        Assert.notNull(userId, "用户信息不存在");
        return iGoodsService.reserveGoods(id, userId.longValue(), number);
    }

    @ApiOperation("首页 - 热销排行榜")
    @GetMapping("/hotList")
    public PageResult<GoodsListVo> hotList(@Validated PageParam pageParam) {
        return iGoodsService.hotList(pageParam);
    }

    /**
     * 限时商品列表
     *
     * @param pageParam 分页参数
     * @param params 搜索参数
     * @return Object
     */
    @GetMapping("/listLimited")
    public Object listLimited(@Validated PageParam pageParam,
                       @RequestParam Map<String, String> params) {
        PageResult<LimitedTimeGoodsListVo> list = iGoodsService.listLimited(pageParam, params);
        return AjaxResult.success(list);
    }
}
